package com.blb.zy_community.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.zy_community.entity.SysMenu;
import com.blb.zy_community.entity.SysRole;
import com.blb.zy_community.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author Reuben
 * @since 2023-06-19
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    //个人主页
    Page<SysUser> selectUserById(Page<?> page,String userName);



    /**
     * 分页查询
     * @return
     */

    Page<SysUser> SelectSysUserPage(Page<SysUser> page,String userName,String phonenumber,String status,String startTime,String endTime,Long deptId);



    @Select("select r.* from sys_role r join sys_user_role ur\n" +
            "on r.role_id = ur.role_id\n" +
            "join sys_user u \n" +
            "on u.user_id = ur.user_id\n" +
            "where u.user_name = #{username}")
    List<SysRole> selectRolesByUsername(String username);



    @Select("select p.* from sys_menu p join sys_role_menu rp \n" +
            "on p.menu_id = rp.menu_id\n" +
            "join sys_role r on r.role_id = rp.role_id\n" +
            "join sys_user_role ur on r.role_id = ur.role_id\n" +
            "join sys_user u on ur.user_id = u.user_id\n" +
            "where u.user_name = #{username}")
    List<SysMenu> selectPermissionByUsername(String username);




    /**
     * 添加
     */
    void insertSysUser(SysUser sysUser);


    /**
     * 修改用户状态
     */
    @Update("update sys_user set status = #{statusId} where user_id = #{userId}")
    void updateStatus(Long statusId,Long userId);

    /**
     * 批量删除
     * @param userIds
     */
    void deleteByUserIds(Long[] userIds);

    /**
     * 重置用户密码
     * @param password
     */
    @Update("update sys_user set password=#{password} where user_id = #{userId}")
    void updatePwd(Long userId ,String password);
    @Select("select * from sys_user where user_name=#{userName}")
        SysUser selectSysUserByUserName(String username);

    Page<SysUser> selectSysUserPage2(Page<Object> objectPage, String userName, String phonenumber, String status, String startTime, String endTime, Long deptId);
}
